package com.ruan.controller;

import com.ruan.common.R;
import com.ruan.pojo.Project;
import com.ruan.pojo.ProjectAssignments;
import com.ruan.service.ProjectAssignmentsService;
import com.ruan.service.ProjectService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/projectAssignments")
public class ProjectAssignmentsController {
    @Autowired
    private ProjectAssignmentsService projectAssignmentsService;

    @Autowired
    private ProjectService projectService;

    //新增项目分配记录
    @PostMapping("/saveAssignmentInfo")
    public R<String> save(@RequestBody ProjectAssignments projectAssignments){
        log.info("新增项目分配记录，项目分配信息：{}",projectAssignments.toString());
        projectAssignmentsService.save(projectAssignments);//把这个对象存进去
        //项目表要填充之前空着的项目负责人id
        Project project = projectService.getById(projectAssignments.getProjectId());
        project.setEmployeeId(projectAssignments.getEmployeeId());
        if(projectAssignments!=null){
            project.setCost(projectAssignments.getProjectBudget());//工具预计总预算
        }
        projectService.updateById(project);

//        projectToolAssignmentService.save()
//save方法继承自mybatis-plus的父接口IService（看看application.yml文件）,可以直接调用
        return R.success("项目分配成功");
    }
}
